package com.yz.bi.mapper;

import com.yz.common.pojo.Database;
import com.yz.common.pojo.DbLink;
import com.yz.common.pojo.LogSheet;
import com.yz.dba.vo.DatabaseInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 段成
 * @date 2019/12/12 - 10:08
 */
@Mapper
public interface BiMapper {
    @Select("select * from t_dbLink where dstatus=1")
    List<DbLink> getLinkName();

    @Select("select id,databaseName from t_database where linkId=#{linkId} and dstatus=1")
    List<Database> getDatabaseByLinkId(@Param("linkId") Integer linkId);

    @Select("SELECT databaseName FROM t_database WHERE id=#{databaseId} and dstatus=1")
    String getDatabaseNameByDatabaseId(@Param("databaseId") Integer databaseId);

    @Select("SHOW TABLES FROM ${databaseName}")
    List<String> getTablesByDatabaseName(@Param("databaseName") String databaseName);

    @Select("SELECT db.username,db.pass,db.databaseName, " +
            "dbl.driver,dbl.ip,dbl.`port`,dbl.dbTypeName FROM t_database db INNER JOIN t_dblink dbl " +
            "ON db.linkId=dbl.id AND db.id = #{databaseId}")
    DatabaseInfo getDatabaseInfo(@Param("databaseId") Integer databaseId);

}
